package cn.pping.product.service.impl;

import cn.pping.basic.exception.BusinessExeption;
import cn.pping.basic.util.BaiduAuditUtils;
import cn.pping.pet.domain.Pet;
import cn.pping.pet.domain.PetDetail;
import cn.pping.product.domain.Product;
import cn.pping.product.domain.ProductDetail;
import cn.pping.product.mapper.ProductDetailMapper;
import cn.pping.product.mapper.ProductMapper;
import cn.pping.product.service.IProductService;
import cn.pping.basic.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author pping
 * @since 2022-08-06
 */
@Service
public class ProductServiceImpl extends BaseServiceImpl<Product> implements IProductService {
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private ProductDetailMapper productDetailMapper;


    @Override
    public void update(Product product) {
        Boolean aBoolean = BaiduAuditUtils.TextCensor(product.getName());
        if(aBoolean != true ){
            throw new BusinessExeption("输入内容合法");
        }
        productMapper.update(product);
        productDetailMapper.update(product.getProductDetail());
    }

    @Override
    public void add(Product product) {
        Boolean aBoolean = BaiduAuditUtils.TextCensor(product.getName());
        if(aBoolean != true ){
            throw new BusinessExeption("输入内容合法");
        }
        productMapper.add(product);
        product.setState(0L);
        productMapper.update(product);
        ProductDetail productDetail = product.getProductDetail();
        productDetail.setProduct_id(product.getId());
        productDetailMapper.add(productDetail);

    }

    @Override
    public void onSale(List<Long> ids) {
        Date date = new Date();
        productMapper.onSale(ids ,date);
    }

    @Override
    public void offSale(List<Long> ids) {
        Date date = new Date();
        productMapper.offSale(ids ,date);
    }
}
